<?php

declare(strict_types=1);

namespace App\Request\Topic;

use App\Request\BaseCommonRequest;
use Hyperf\Context\Context;
use Hyperf\Validation\Request\FormRequest;

class TopicRequest extends BaseCommonRequest
{
    public function authorize(): bool
    {
        return true;
    }

    protected array $scenes = [
        'create' => ['from', 'version_code', 'channel', 'content', 'request_type'],
        'check' => ['from', 'version_code', 'channel', 'request_type'],
        'list' => ['page', 'type', 'from', 'version_code', 'channel'],
        'detail' => ['page', 'topic_id'],
        'delete' => ['topic_id']
    ];

    public function rules(): array
    {
        // return [
        //     'page' => 'required',
        //     'type' => 'required',
        //     'from' => 'required',
        //     'version_code' => 'required',
        //     'channel' => 'required',
        //     'request_type' => 'required|in:1,2',
        //     'content' => 'required',
        //     'topic_id' => 'required|array',
        // ];
        return [
            'create' => [
                'from' => 'required',
                'version_code' => 'required',
                'channel' => 'required',
                'content' => 'required',
                'request_type' => 'required|in:1,2',
            ],
            'check' => [
                'from' => 'required',
                'version_code' => 'required',
                'channel' => 'required',
                'request_type' => 'required|in:1,2',
            ],
            'list' => [
                'page' => 'required',
                'type' => 'required',
                'from' => 'required',
                'version_code' => 'required',
                'channel' => 'required',
            ],
            'detail' => [
                'page' => 'required',
                'topic_id' => 'required|array',
            ],
            'delete' => [
                'topic_id' => 'required|array',
            ]
        ];
    }

    /**
     * 获取已定义验证规则的错误消息
     */
    public function messages(): array
    {
        $language = Context::get('language', 'en');
        if ($language == 'zh-cn') {
            return [
                'required' => ':attribute不能为空',
                'in' => ':attribute格式错误',
                'array' => '帖子id必须是数组',
            ];
        } elseif ($language == 'zh-hk') {
            return [
                'required' => ':attribute不能為空',
                'in' => ':attribute格式錯誤',
                'array' => '帖子id必須是數組',
            ];
        } else {
            return [
                'required' => ':attribute field is required.',
                'in' => ':attribute format error',
                'array' => 'topic_id must be array',
            ];
        }

    }

}